package com.ljb.android.comm.img.core

import android.graphics.Bitmap
import com.bumptech.glide.load.Transformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CenterInside
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.FitCenter
import java.util.*

class ImgScaleTypeFactory {

    companion object {

        @JvmStatic
        var mCache = WeakHashMap<ImgScaleType, Transformation<Bitmap>>()

        @JvmStatic
        fun foundScaleMode(type: ImgScaleType): Transformation<Bitmap> {
            var scaleType = mCache[type]
            if (scaleType == null) {
                scaleType = when (type) {
                    ImgScaleType.CenterCrop -> CenterCrop()
                    ImgScaleType.CenterInside -> CenterInside()
                    ImgScaleType.CircleCrop -> CircleCrop()
                    ImgScaleType.FitCenter -> FitCenter()
                }
                mCache[type] = scaleType
            }
            return scaleType
        }
    }
}